import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtCharts 2.0
import QtQuick.Dialogs 1.2

Grid {
    id: mtfGridView
    columns: 1
    rows: 2
    width: 1000
    height: 800
    Frame {
        width: mtfGridView.width
        height: 100
        RowLayout {
            Button {
                text: qsTr("MTF Loop Test Start")
                onClicked: {
                    tem.runSingleCmd(aaCore, "performMTFLoopTest")
                }
            }
            Button {
                text: qsTr("Clear Result")
                onClicked: {
                    tem.runSingleCmd(aaCore, "performClearMTFLoopTestResult")
                }
            }
            Button {
                text: qsTr("Stop MTF Loop Test")
                onClicked: {
                    tem.runSingleCmd(aaCore, "performStopMTFLoopTest")
                }
            }
        }
    }

    Frame {
        width: mtfGridView.width
        height: mtfGridView.height
        ChartView {
            id: spline11
            anchors.fill: parent
            title: "MTF Loop Test Result "
            antialiasing: true
            theme: ChartView.ChartThemeDark
            legend.alignment: Qt.AlignBottom
            margins.top: 50
            ValueAxis {
                id: axisY
                titleText: "SFR"
                min: 0
                max: 100
                tickCount: 10
                gridVisible: true
            }
            ValueAxis {
                titleText: "Sample"
                id: axisX
                tickCount: 1
                gridVisible: true
            }
            SplineSeries {
                name: "CC "
                id: ccSeries
                axisX: axisX
                axisY: axisY
            }
            SplineSeries {
                name: "UL "
                id: ulSeries
                axisX: axisX
                axisY: axisY
            }
            SplineSeries {
                name: "UR "
                id: urSeries
                axisX: axisX
                axisY: axisY
            }
            SplineSeries {
                name: "LL "
                id: llSeries
                axisX: axisX
                axisY: axisY
            }
            SplineSeries {
                name: "LR "
                id: lrSeries
                axisX: axisX
                axisY: axisY
            }
            Connections {
                target: mtfLoopTestData
                onWValueChanged: {
                    console.log(mtfLoopTestData.wCCValue.x + " " + mtfLoopTestData.wCCValue.y)
                    ccSeries.append(mtfLoopTestData.wCCValue.x, mtfLoopTestData.wCCValue.y)
                    ulSeries.append(mtfLoopTestData.wULValue.x, mtfLoopTestData.wULValue.y)
                    urSeries.append(mtfLoopTestData.wURValue.x, mtfLoopTestData.wURValue.y)
                    llSeries.append(mtfLoopTestData.wLLValue.x, mtfLoopTestData.wLLValue.y)
                    lrSeries.append(mtfLoopTestData.wLRValue.x, mtfLoopTestData.wLRValue.y)
                    axisX.min = ccSeries.at(0).x
                    axisX.max = ccSeries.at(ccSeries.count - 1).x
                }
                onWValueClear: {
                    ccSeries.clear()
                    ulSeries.clear()
                    urSeries.clear()
                    llSeries.clear()
                    lrSeries.clear()
                }
            }
        }
    }
}
